<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>location对象</h1>
    <ul>
        <li>使用location对象可以完成页面请求（跳转）、页面刷新功能</li>
    </ul>
    <button onclick="handleAssign1()">请求百度1</button>
    <button onclick="handleAssign2()">请求百度2</button>
    <br>
    <button onclick="hanndleReload1()">刷新1</button>
    <button onclick="hanndleReload2()">刷新2</button>
    <br>
    <button onclick="handleReplace()">请求（替换）百度1</button>
    <h2>assign和replace</h2>
    <ul>
        <li>assign: 会留下历史记录</li>
        <li>replace: 不会留下历史记录（下个页面，后退不会退到当前页面）</li>
    </ul>
    <script>
        function handleAssign1() {
            location.assign("https://www.baidu.com");
        }

        function handleAssign2() {
            // location.href = "https://www.baidu.com";
            // 以上可以简写：
            location = "https://www.baidu.com/s?wd=汽车";
        }

        function hanndleReload1() {
            location.reload();
        }

        function hanndleReload2() {
            // location.href = location.href;
            // 以上可以简写：
            location = location;
        }

        function handleReplace() {
            location.replace("https://www.baidu.com");
        }
    </script>
</body>
</html>